﻿<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:output encoding="utf-8" method="xml" indent="yes" omit-xml-declaration="yes" />
    <xsl:template match="/">
        <xsl:element name="xml">
            <xsl:element name="Data">
                <xsl:element name="Lines">
                    <xsl:for-each select="//*/Line[@VendorID!='']">
                        <xsl:sort select="@DisplayOrder" data-type="number" />
                        <xsl:copy-of select="." />
                        <xsl:variable name="MediaID">
                            <xsl:value-of select="@ID" />
                        </xsl:variable>
                        <xsl:for-each select="//*/Line[@VendorID!='' and @ID=$MediaID]">
                            <xsl:sort select="@DisplayOrder" data-type="number" />
                            <xsl:copy-of select="." />
                        </xsl:for-each>
                    </xsl:for-each>
                </xsl:element>
                <xsl:element name="DisplayFormat">
                    <xsl:attribute name="NavLabel">
                        <xsl:value-of select="//*/DisplayFormat/@NavLabel" />
                    </xsl:attribute>
                    <xsl:attribute name="LangID">
                        <xsl:value-of select="//*/DisplayFormat/@LangID" />
                    </xsl:attribute>
                    <xsl:for-each select="//*/DisplayFormat/Display">
                        <xsl:copy-of select="." />
                    </xsl:for-each>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>